package com.borqs.samples;

import android.util.*;
import android.content.*;

public class WakelockSampler extends ASampler {
    private final static String TAG = "WakelockSampler";

    public WakelockSampler(DBHelper helper) {
        super(helper);
    }

    @Override
    public void sample(long sample_id) {
        String[] m = WakelockServiceProvider.getNowMaxPartialWl();
        if (m != null) {
            Log.d(TAG, "now max partial wakelock:" + m[0] + ":" + m[1]);
            if (!m[0].equals("")) {
                /* if no partial wakelock,not save to db */
                dbSave(sample_id, m);
            }
        }
    }

    private void dbSave(long sample_id, String[] ps) {
        ContentValues cv = new ContentValues();
        cv.put("tag", ps[0]);
        cv.put("time_length", ps[1]);
        cv.put("sample_id", sample_id);
        helper.getWritableDatabase().insert("wakelock_samples", null, cv);
    }
    
}
